home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / point / src / main.c next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  8.1 KB  |  341 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <winb.h>
  5. #include <te.h>
  6. #include <fntb.h>
  7. #include <gui.h>
  8. #include <egb.h>
  9. #include <guidbg.h>
  10.  
  11. char    *guiEgbPtr ;            /*    EGB のワークアドレス    */
  12.  
  13. #define    MinMem (1024*20)    /*    必要とする動作メモリの定義    */
  14.  
  15. char    *guiEgbPtr ;
  16.  
  17. /*    exitFunc関数の復帰値                    */
  18. int        exitFuncRet = ILLEGAL_FUNCTION ;
  19.  
  20. /*    alertMemFunc関数の追い越し禁止フラグ    */
  21. static int        alertMemFlag = FALSE ;
  22.  
  23. /*    アラートメッセージ                        */
  24. static char    *alertStrMem[] = 
  25.                 {"Point:\nメモリが不足しています", "確認"};
  26.  
  27. /****************************************************************/
  28. /*    メモリ不足時のアラート関数(イベント登録関数)                */
  29. /****************************************************************/
  30. void alertMemFunc()
  31. {
  32.     /*    メモリ不足のアラート表示    */
  33.     MMI_CallMessage(MMI_GetApliId(), GM_ALERT, 
  34.                         AM_ALERT1 | AM_ALERTB0E,(int)alertStrMem) ;
  35.  
  36.     /* alertMemFunc関数の追い越し禁止解除    */
  37.     alertMemFlag = FALSE ;
  38. }
  39.  
  40. int userFunc(apliId, messId, info, data)
  41. int    apliId;
  42. int    messId;
  43. int    info;
  44. int    data;
  45. {
  46.     register int    ret;
  47.  
  48.     ret = ILLEGAL_FUNCTION;
  49.  
  50.     switch(messId)
  51.     {
  52.         /*    他のアプリから制御がきた    */
  53.         case    GM_WAKE :
  54.         {
  55.             EVENT    ev ;
  56.  
  57.             /*    alertMemFunc関数の追い越し禁止判定            */
  58.             if(alertMemFlag != FALSE)
  59.                 break ;
  60.  
  61.             /*    動作メモリのチェック                        */
  62.             if(TL_checkMemory(1) * 4096 < MinMem)
  63.             {
  64.                 /*    alertMemFunc関数の追い越し禁止    */
  65.                 alertMemFlag = TRUE ;
  66.  
  67.                 /*    メモリ不足の場合はアラート処理関数をイベント登録する    */
  68.                 MMI_FlushEvnt() ;
  69.                 ev.what = EVEXEC ;
  70.                 ev.shift = 0 ;
  71.                 ev.info = (int)alertMemFunc ;
  72.                 MMI_SetEvnt(&ev) ;
  73.                 break ;
  74.             }
  75.             break ;
  76.         }
  77.  
  78.         /*    他のアプリに制御を移す    */
  79.         case    GM_SLEEP :
  80.             break ;
  81.  
  82.         case    GM_QUIT :
  83.             MMI_SetHaltFlag(TRUE);
  84.             ret = NOERR ;
  85.             break;
  86.     }
  87.  
  88.     return(ret);
  89. }
  90.  
  91. void main( argc, argv )
  92.  
  93. int  argc ;
  94. char *argv[] ;
  95. {
  96.     MMICTRL ctrl ; 
  97.  
  98.     ctrl.page0 = SCREEN16 ;            /*    16色1画面に設定する    */
  99.     ctrl.page1 = SCREENUNUSED ;        /*    裏画面は使用しない        */
  100.     ctrl.writePage = 0 ;            /*    page0 を書き込みページ    */
  101.     ctrl.displayPage = 1 ;            /*    1画面表示                */
  102.     ctrl.priority = 0 ;
  103.     ctrl.mode = SCREENAVAILABLE ;    /*    解像度無依存            */
  104.     ctrl.width = SCREENEXPAND ;        /*    解像度無依存拡張指定    */
  105.     ctrl.size = 0 ;                    /*    メモリの初期化は         */
  106.     ctrl.ptr = NULL ;                /*    GUIライブラリに任せる        */
  107.     ctrl.asize = 0 ;                /*    アプリケーションで必要とする    */
  108.     ctrl.aptr = NULL ;                /*    初期メモリは無し        */
  109.     ctrl.move.lupx = -16384 ;        /*    移動枠は                */
  110.     ctrl.move.lupy = 22 ;            /*    (-16384,22)-            */
  111.     ctrl.move.rdwx = 16383 ;        /*            (16383,16383)    */
  112.     ctrl.move.rdwy = 16383 ;
  113.     ctrl.white = 15 ;                /*    白色は   15 番            */
  114.     ctrl.black = 8 ;                /*    黒色は    0 番            */
  115.     ctrl.gray = 7 ;                    /*    灰色は    7 番            */
  116.     ctrl.xor = 7 ;                    /*    反転色は  7 番            */
  117.  
  118.     extern int APL_init() ;
  119.  
  120.     /*    初期化処理    */
  121.     if (MMI_Open( &ctrl ) == NOERR)
  122.     {
  123.         /*    初期化に成功すればメインループに入る.    */
  124.         if (APL_init( argc, argv ) == NOERR)
  125.         {
  126.             /*    動作メモリのチェック    */
  127.             if(TL_checkMemory(1) * 4096 < MinMem)
  128.             {
  129.                 /*    alertMemFunc関数の追い越し禁止    */
  130.                 alertMemFlag = TRUE ;
  131.  
  132.                 /*    メモリ不足のアラート表示    */
  133.                 alertMemFunc() ;
  134.             }
  135.  
  136.             MMI_ExecSystem() ;
  137.         }
  138.     }
  139.  
  140.     /*    終了処理    */
  141.     MMI_Close() ;
  142.  
  143. }
  144.  
  145. int APL_init( argc, argv )
  146.  
  147. int  argc ;
  148. char *argv[] ;
  149. {
  150.     extern MMIINIT    initDataMWINDOW ;
  151.  
  152.     register int    ret ;
  153.  
  154.     extern void setPointFunc() ;
  155.     extern int windowId ;
  156.  
  157.     char tmenuPaletteWork[ 1536 ] ;
  158.  
  159.     /*    ハイパ型部品の初期化            */
  160.     if ((ret = MMI_initHyper()) < 0)
  161.         return ret ;
  162.     /*    ダイアログ型部品の初期化        */
  163.     if ((ret = MMI_initDialogL40()) < 0)
  164.         return ret ;
  165.     /*    ウインドウ型部品の初期化        */
  166.     if ((ret = MMI_initWindowL40()) < 0)
  167.         return ret ;
  168.     /*    メッセージ型部品の初期化        */
  169.     if ((ret = MMI_initMessageL40()) < 0)
  170.         return ret ;
  171.     /*    ボタン型部品の初期化            */
  172.     if ((ret = MMI_initButtonL40()) < 0)
  173.         return ret ;
  174.     /*    アイコンボタン型部品の初期化    */
  175.     if ((ret = MMI_initIconL40()) < 0)
  176.         return ret ;
  177.  
  178.     /*    背景データの初期化                        */
  179.  
  180.     /*    データの登録        */
  181.     if ((ret = MMI_Init(&initDataMWINDOW)) < 0)
  182.         return ret ;
  183.  
  184.     /* TownsMENUのメュー色の設定   */
  185.     EGB_tmenuPalette2( tmenuPaletteWork ) ;
  186.  
  187.     /*  windowId(window型部品)を実行可能状態にする  */
  188.     MMI_SendMessage( windowId, MM_WAKE, 0 ) ;
  189.  
  190.     /* イベントが何も無いときに実行する関数の登録 */
  191.     MMI_SetIdleTaskFunc( setPointFunc ) ;
  192.  
  193.     /*  パラメータのよる座標の変更  */
  194.     initPoint( argc, argv ) ;
  195.  
  196.     /*    背景を表示する                            */
  197.     MMI_SendMessage(MMI_GetBaseObj(), MM_SHOW, 0) ;
  198.  
  199.     MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
  200.     MMI_CallMessage(MMI_GetApliId(), GM_TITLE, (int)"Point", 0);
  201.  
  202.     return NOERR ;
  203. }
  204.  
  205. int initPoint( argc, argv )
  206.  
  207. int  argc ;
  208. char *argv[] ;
  209. {
  210.     extern int windowId ;
  211.  
  212.     HYPER hyp ;
  213.  
  214.     int x ;
  215.     int y ;
  216.     int h ;
  217.     int w ;
  218.  
  219.     int hmin = 52  ; /* Window型部品の最小の高さ  */
  220.     int hmax = 480 ; /*  Window型部品の最大の高さ  */
  221.  
  222.     int wmin = 81  ; /*  Window型部品の最小の幅    */
  223.     int wmax = 640 ; /*  Window型部品の最大の幅    */
  224.  
  225.     int dx ;
  226.     int dy ;
  227.  
  228.     MMI_SendMessage( windowId, MM_GETHYPER, 1, &hyp ) ;
  229.  
  230.     if(( argv[1] != NULL )&&( argv[2] != NULL )&&( argv[3] != NULL )&&( argv[4] != NULL ))
  231.     {
  232.         x = atoi( argv[1] ) ;
  233.         y = atoi( argv[2] ) ;
  234.         w = atoi( argv[3] ) ;
  235.         h = atoi( argv[4] ) ;
  236.  
  237.         /* パラメータのチェック */
  238.         if( h < hmin ) h = hmin ;
  239.         if( h > hmax ) h = hmax ;
  240.  
  241.         if( w < wmin ) w = wmin ;
  242.         if( w > wmax ) w = wmax ;
  243.  
  244.         if( x     <    0 ) x =    0 ;      /* 解像度のチェック(マニュアルを見るの) */
  245.         if( x     > 1024 ) x = 1024 - w ;  /*  が面倒くさいので。                     */
  246.  
  247.         if( y     <   22 ) y =   22 ;
  248.         if( y + h >  768 ) y =  768 - h ;
  249.  
  250.         dx = hyp.fr.lupx - x ;  /* 移動幅の計算 */
  251.         dy = hyp.fr.lupy - y ;  /* 移動幅の計算 */
  252.  
  253.         MMI_SendMessage( windowId, MM_MOVE, 2, -dx, -dy ) ;
  254.  
  255.         resizeWindowFunc( h, w ) ;
  256.     }
  257.  
  258.     return NOERR ;
  259. }
  260.  
  261. int resizeWindowFunc( h, w )
  262.  
  263. int h ;
  264. int w ;
  265. {
  266.     extern int windowId ;
  267.     extern int xPointMessageId ;
  268.     extern int yPointMessageId ;
  269.     extern int xMessageId ;
  270.     extern int yMessageId ;
  271.  
  272.     HYPER whyp ;
  273.     HYPER xhyp ;
  274.  
  275.     int mx = 32 ;  /* 座標数字のメッセージ型部品の横幅 */
  276.     int px = 16 ;  /* 座標文字のメッセージ型部品の横幅 */
  277.     int hy = 16 ;  /* 座標数字のメッセージ型部品&座標文字のメッセージ型部品の縦の幅 */
  278.     int wh = 17 ;  /* window型部品のタイトルバーの縦幅 */
  279.     int sd =  3 ;  /* window型部品の影の縦幅 */
  280.  
  281.     int spx ;       /* メッセージ型部品の基本x座標 */
  282.     int spy ;       /* メッセージ型部品の基本y座標 */
  283.  
  284.     /* windowの幅の調整 */
  285.     MMI_SendMessage( windowId, MM_GETHYPER, 1, &whyp ) ;
  286.  
  287.     whyp.fr.rdwx = whyp.fr.lupx + w ;
  288.     whyp.fr.rdwy = whyp.fr.lupy + h ;
  289.  
  290.     MMI_SendMessage( windowId, MM_SETHYPER, 1, &whyp ) ;
  291.  
  292.  
  293.     spx = whyp.fr.lupx + ( w-mx-px )/2 ;
  294.     spy = whyp.fr.lupy + ( h-sd-wh-hy*2  )/2 + wh ;
  295.  
  296.     /* 幅の調整のよるx座標表示数字のメッセージ型部品の座標の調整 */
  297.     MMI_SendMessage( xMessageId, MM_GETHYPER, 1, &xhyp ) ;
  298.  
  299.     xhyp.fr.lupx = spx + px ;
  300.     xhyp.fr.lupy = spy ;
  301.     xhyp.fr.rdwx = xhyp.fr.lupx + mx ;
  302.     xhyp.fr.rdwy = xhyp.fr.lupy + hy ;
  303.  
  304.     MMI_SendMessage( xMessageId, MM_SETHYPER, 1, &xhyp ) ;
  305.  
  306.  
  307.     /* 幅の調整のよるy座標表示数字のメッセージ型部品の座標の調整 */
  308.     MMI_SendMessage( yMessageId, MM_GETHYPER, 1, &xhyp ) ;
  309.  
  310.     xhyp.fr.lupx = spx + px ;
  311.     xhyp.fr.lupy = spy + hy ;
  312.     xhyp.fr.rdwx = xhyp.fr.lupx + mx ;
  313.     xhyp.fr.rdwy = xhyp.fr.lupy + hy ;
  314.  
  315.     MMI_SendMessage( yMessageId, MM_SETHYPER, 1, &xhyp ) ;
  316.  
  317.  
  318.     /* 幅の調整のよる「x:」のメッセージ型部品の座標の調整 */
  319.     MMI_SendMessage( xPointMessageId, MM_GETHYPER, 1, &xhyp ) ;
  320.  
  321.     xhyp.fr.lupx = spx ;
  322.     xhyp.fr.lupy = spy ;
  323.     xhyp.fr.rdwx = xhyp.fr.lupx + px ;
  324.     xhyp.fr.rdwy = xhyp.fr.lupy + hy ;
  325.  
  326.     MMI_SendMessage( xPointMessageId, MM_SETHYPER, 1, &xhyp ) ;
  327.  
  328.  
  329.     /* 幅の調整のよる「y:」のメッセージ型部品の座標の調整 */
  330.     MMI_SendMessage( yPointMessageId, MM_GETHYPER, 1, &xhyp ) ;
  331.  
  332.     xhyp.fr.lupx = spx ;
  333.     xhyp.fr.lupy = spy + hy ;
  334.     xhyp.fr.rdwx = xhyp.fr.lupx + px ;
  335.     xhyp.fr.rdwy = xhyp.fr.lupy + hy ;
  336.  
  337.     MMI_SendMessage( yPointMessageId, MM_SETHYPER, 1, &xhyp ) ;
  338.  
  339.     return NOERR ;
  340. }
  341.